#pragma once

#include "ReplyAction.h"

#include "InputPin.h"
#include "Trigger.h"

namespace uml {

ReplyAction::ReplyAction(const QString& umlType)
    : Action(umlType) {}

void ReplyAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Action::fromJson(json, errorList);
    replyToCall_ = JsonSerializable::create<Trigger>(json.value("replyToCall"), errorList);

    JsonSerializable::fromJsonArray(replyValues_, "replyValues", json, errorList);
    returnInformation_ = JsonSerializable::create<InputPin>(json.value("returnInformation"), errorList);

}

void ReplyAction::toJson(QJsonObject& json) {
    Action::toJson(json);
    if (replyToCall_) {
        QJsonObject replyToCall_json;
        replyToCall_->toJson(replyToCall_json);
        json.insert("replyToCall", replyToCall_json);
    }
    JsonSerializable::toJsonArray(replyValues_, "replyValues", json);
    if (returnInformation_) {
        QJsonObject returnInformation_json;
        returnInformation_->toJson(returnInformation_json);
        json.insert("returnInformation", returnInformation_json);
    }
}

/// <summary>
/// replyToCall getter
/// The Trigger specifying the Operation whose call is being replied to.
/// </summary>
shared_ptr<Trigger> ReplyAction::replyToCall() const {
    return replyToCall_;
}

/// <summary>
/// replyToCall setter
/// The Trigger specifying the Operation whose call is being replied to.
/// </summary>
void ReplyAction::setReplyToCall(shared_ptr<Trigger> value) {
    replyToCall_ = value;
}

/// <summary>
/// replyValues getter
/// A list of InputPins providing the values for the output (inout, out, and return)
/// Parameters of the Operation. These values are returned to the caller.
/// </summary>
vector<shared_ptr<InputPin>>& ReplyAction::replyValues() {
    return replyValues_;
}

/// <summary>
/// returnInformation getter
/// An InputPin that holds the return information value produced by an earlier
/// AcceptCallAction.
/// </summary>
shared_ptr<InputPin> ReplyAction::returnInformation() const {
    return returnInformation_;
}

/// <summary>
/// returnInformation setter
/// An InputPin that holds the return information value produced by an earlier
/// AcceptCallAction.
/// </summary>
void ReplyAction::setReturnInformation(shared_ptr<InputPin> value) {
    returnInformation_ = value;
}

} // namespace uml
